package pl.edu.agh.sius.controller;

import pl.edu.agh.sius.utils.FacesHelper;

public abstract class ConcernController {

	protected String concernTitle;
	protected String[] stepTitles;
	protected int stepsNo;
	protected int step = 0;

	public String abort() {
		restart();
		return "restart";
	}

	public boolean getAbortRendered() {
		return true;
	}

	public String getConcernTitle() {
		return concernTitle;
	}

	public String getStepTitle() {
		return "Krok " + (step + 1) + "/" + stepsNo + " - " + stepTitles[step];
	}

	public String next() {
		if (step < stepsNo - 1) {
			++step;
			return "step" + step;
		} else {
			FacesHelper.addMessage("Błąd w nawigacji.", null);
			return null;
		}
	}

	public boolean getNextRendered() {
		return step < stepsNo - 1;
	}

	public String previous() {
		if (step > 0) {
			--step;
			return "step" + step;
		} else {
			FacesHelper.addMessage("Błąd w nawigacji.", null);
			return null;
		}
	}

	public boolean getPreviousRendered() {
		return step > 0;
	}

	public abstract String submit();
	
	public boolean getSubmitRendered() {
		return step == stepsNo - 1;
	}

	public void restart() {
		step = 0;
	}

	// upload
	protected InputFileController inputFileController;
	// popup
	protected PopupController popupController;

	public ConcernController() {
		super();
		inputFileController = FacesHelper.getBeanB("inputFileController",
				InputFileController.class);
		popupController = FacesHelper.getBeanB("popupController",
				PopupController.class);
	}

	public boolean getCanUpload() {
		boolean b = inputFileController != null;
		if (b == false) {
			FacesHelper.addMessage("Moduł uploadu niesprawny.", null);
		}
		return b;
	}

}
